package com.fenghongzhang.day001;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import org.w3c.dom.Text;

public class MyDialog extends Dialog {
    private static final String TAG = "MyDialog";

    private TextView title;
    private TextView message;
    private Button no;
    private Button yes;



    //中转的字符串
    private String messageStr;

    public String getMessageStr() {
        return messageStr;
    }

    public void setMessageStr(String messageStr) {
        this.messageStr = messageStr;
    }

    private String titleStr;


    public String getTitleStr() {
        return titleStr;
    }

    public void setTitleStr(String titleStr) {
        this.titleStr = titleStr;
    }

    public MyDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //把布局和组件关联起来
        setContentView(R.layout.dialog_layout);

        title = (TextView) findViewById(R.id.title);
        message = (TextView) findViewById(R.id.message);
        no = (Button) findViewById(R.id.no);
        yes = (Button) findViewById(R.id.yes);

//        title.setText("hehe");

        if(titleStr != null){
            title.setText(titleStr);
        }

        //给组件赋值
        if(messageStr !=null){
            message.setText(messageStr);
        }


        //4,显示点击事件
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "onClick: 点了");
                //接口中,一个方法
                onYesClick.onClick();
                dismiss();
            }
        });

        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onNoClick.onClick();
                dismiss();
            }
        });

    }



    //取消的接口
    public interface OnNoClick{
        void onClick();
    }

    private OnNoClick onNoClick;

    public OnNoClick getOnNoClick() {
        return onNoClick;
    }

    public void setOnNoClick(OnNoClick onNoClick) {
        this.onNoClick = onNoClick;
    }

    //1, 定义确定接口
    public interface OnYesClick{
        void onClick();
    }

    //2,声明成员属性
    private OnYesClick onYesClick;


    //3,set,get方法
    public OnYesClick getOnYesClick() {
        return onYesClick;
    }

    public void setOnYesClick(OnYesClick onYesClick) {
        this.onYesClick = onYesClick;
    }
}
